<!--
 * @Author: Wayne 13235388225@163.com
 * @Date: 2023-10-12 11:02:45
 * @LastEditors: Wayne 13235388225@163.com
 * @LastEditTime: 2023-10-12 11:29:27
 * @FilePath: \Jkc-app-front-new\src\views\complaint\complaint.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!--
 * @Author: Wayne 13235388225@163.com
 * @Date: 2023-10-12 11:02:45
 * @LastEditors: Wayne 13235388225@163.com
 * @LastEditTime: 2023-10-12 11:04:49
 * @FilePath: \Jkc-app-front-new\src\views\complaint\complaint.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container">
    <div class="view-title">投诉建议管理</div>
    <!-- table -->

    <el-table
      :data="complaintTableData"
      v-loading="loading"
      element-loading-text="正在加载中"
      :header-cell-style="{
        borderColor: '#F0F0F0',
        height: '51px',
        background: '#F0F0F0',
        color: '#333',
      }"
      :row-style="{ height: '51px' }"
      :cell-style="{ borderColor: '#F0F0F0' }"
      style="width: 100%; margin-top: 20px"
    >
      <el-table-column prop="id" label="id" width="60" align="center">
      </el-table-column>
      <el-table-column prop="user_id" label="用户id" align="center">
      </el-table-column>
      <el-table-column prop="type" label="类型" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.type == 0">页面闪退</el-tag>
          <el-tag type="info" v-if="scope.row.type == 1">操作体验</el-tag>
          <el-tag type="warning" v-if="scope.row.type == 2">账号问题</el-tag>
          <el-tag type="danger" v-if="scope.row.type == 3">其他投诉</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="text" label="内容" align="center">
      </el-table-column>
      <el-table-column prop="image" label="图片(点击可查看大图)" align="center">
        <template slot-scope="scope">
          <img
            v-if="scope.row.image"
            :src="scope.row.image"
            alt=""
            @click="handleCheckImg(scope.row.image)"
            style="width: 80px; height: 80px"
          />
        </template>
      </el-table-column>
      <el-table-column prop="created_at" label="创建时间" align="center">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-button
            @click="handleDelete(scope.row)"
            type="text"
            size="small"
            v-permission="['complaint:delete']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <div class="page_box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNow"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <!-- 查看大图弹窗 -->
    <el-dialog
      title="查看大图"
      :visible.sync="dialogVisibleCheckImg"
      width="40%"
    >
      <div>
        <img :src="checkImg" alt="" style="width: 70%" />
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getAppComplaintList, deleteAppComplaint } from "@/api/complaint.js";
export default {
  name: "Complaint",
  data() {
    return {
      pageNow: 1,
      pageSize: 10,
      total: null,
      complaintTableData: [],
      deleteId: "",
      loading: true,
      checkImg: "",
      dialogVisibleCheckImg: false,
    };
  },
  mounted() {
    this.getAppComplaintList();
  },
  methods: {
    // 获取投诉建议列表
    getAppComplaintList() {
      getAppComplaintList({
        page_now: this.pageNow,
        page_size: this.pageSize,
      }).then((res) => {
        if (res.code == 1) {
          this.loading = false;
          this.complaintTableData = res.data;
          this.total = res.page_info.total_count;
        } else {
          this.loading = false;
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 删除投诉建议
    deleteAppComplaint() {
      deleteAppComplaint({
        ids: this.deleteId,
      }).then((res) => {
        if (res.code == 1) {
          this.$message.success(res.msg);
          this.getAppComplaintList();
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 删除投诉建议
    handleDelete(val) {
      const that = this;
      this.deleteId = val.id;
      this.$confirm("是否确定删除该投诉建议?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          that.deleteAppComplaint();
        })
        .catch(() => {});
    },

    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      this.getAppComplaintList();
    },
    handleCurrentChange(val) {
      this.pageNow = val;
      this.pageSize = 10;
      this.getAppComplaintList();
    },

    // 查看大图
    handleCheckImg(val) {
      this.checkImg = val;
      this.dialogVisibleCheckImg = true;
    },
  },
};
</script>
<style lang="scss" scoped></style>
